package com.bigdata.service.mysql.impl;

import com.bigdata.model.Result;
import com.bigdata.model.SearchModel;
import com.bigdata.mysql.dao.JkfwUserRoleMapper;
import com.bigdata.mysql.entity.JkfwUser;
import com.bigdata.mysql.entity.JkfwUserRole;
import com.bigdata.mysql.entity.JkfwUserRoleExample;
import com.bigdata.service.mysql.JkfwUserRoleService;
import com.bigdata.service.mysql.base.impl.BaseService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * JkfwUserRole的服务接口的实现类
 *
 * @author
 */
@Service
public class JkfwUserRoleServiceImpl extends BaseService<JkfwUserRoleMapper, JkfwUserRole, JkfwUserRoleExample> implements JkfwUserRoleService {
    private final Logger LOG = LogManager.getLogger(this.getClass());


    /**
     * @param roles
     * @param user
     * @return void
     * @author lly
     * @date 2020/3/22 18:42
     * 添加用户和角色表
     */
    @Override
    public void addUserRoleids(List<String> roles, JkfwUser user) {
        for (String roleid : roles) {
            JkfwUserRole role = new JkfwUserRole();
            role.setId(UUID.randomUUID().toString().replace("-", ""));
            role.setRoleId(roleid);
            role.setUserId(user.getUserId());
            dao.insert(role);
        }
    }

    @Override
    public void deleteUserid(JkfwUser user) {
        JkfwUserRoleExample example = new JkfwUserRoleExample();
        example.createCriteria().andUserIdEqualTo(user.getUserId());
        dao.deleteByExample(example);
    }

    @Override
    public Result queryPage(SearchModel searchModel) {
        return null;
    }
}